<!DOCTYPE html>

<head>
    <title>影响报告</title>
    <style>
        #report-page {
            width: 794px;
            height: 1123px;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .page-content {
            width: 95%;
            height: 97%;
        }

        .hospital {
            width: 100%;
            text-align: center;
            margin-top: 20px;
            font-size: 40px;
            font-weight: bold;
        }

        .title {
            width: 100%;
            text-align: center;
            margin-top: 20px;
            font-size: 35px;
        }

        table.info {
            width: 100%;
            border-top: 2px solid #000;
            border-bottom: 1px solid #000;
            margin-top: 20px;
            font-size: 20px;
        }

        table.info tr {
            height: 55px;
        }

        .detail-box {
            margin-top: 20px;
            width: 100%;
            height: 320px;
            /* box-shadow: 0px 0px 5px #000; */
        }

        .detail-box .name {
            font-size: 20px;
            font-weight: bold;
            margin: 8px 0;
        }

        .detail-box .content {
            font-size: 20px;
        }

        .foot {
            width: 100%;
            height: 50px;
            line-height: 60px;
            margin-top: 20px;
            display: flex;
            flex-direction: row;
            font-size: 20px;
            border-top: solid 2px #000;
        }

        .foot .report-doctor {
            flex: 1;
        }

        .foot .report-time {
            width: 250px;
        }

        .warning {
            margin-top: 20px;
            font-size: 20px;
        }
    </style>
</head>


<body>
    <div id="report-page">
        <div class="page-content">
            <div class="hospital">洪洞晋南医院</div>
            <div class="title"><span id="device"></span>影像检查报告</div>
            <table class="info">
                <tr>
                    <td>姓名：<span id="name"></span></td>
                    <td>性别：<span id="gender"></span></td>
                    <td>年龄：<span id="age"></span></td>
                </tr>
                <tr>
                    <td>检查部位：<span id="locate"></span></td>
                    <td>检查时间：<span id="date"></span></td>
                </tr>
            </table>
            <div class="detail-box check">
                <div class="name">检查所见：</div>
                <div class="content"></div>
            </div>
            <div class="detail-box diagnostic">
                <div class="name">诊断结论:</div>
                <div class="content"></div>
            </div>
            <div class="foot">
                <div class="report-doctor">报告医生：</div>
                <div class="report-time">报告时间：<span id="report-time"></span></div>
            </div>
            <div class="warning">
                注：此报告仅供临床医生参考
            </div>
        </div>

    </div>
</body>
<script>
    const getUrlParams = (url) => {
        const reg = /(\w+)=([^&]+)/g;
        const params = {};
        let match;

        while ((match = reg.exec(url)) !== null) {
            params[match[1]] = match[2];
        }

        return params;
    };

    const queryData = () => {
        const { id } = getUrlParams(window.location.href)
        const { row: patient,hospitalName } = window.$.sendSync('STUDY-QUERY', { id })
        document.title = '影像报告【' + patient.name + '】' + new Date().getTime()
        document.querySelector('#device').innerText = patient.device.toUpperCase()
        document.querySelector('#name').innerText = patient.name
        document.querySelector('#gender').innerText = patient.gender == 1 ? '男' : '女'
        document.querySelector('#age').innerText = patient.age + '岁'
        document.querySelector('#locate').innerText = patient.locate
        document.querySelector('#date').innerText = patient.date
        document.querySelector('.check .content').innerHTML = patient.check_content
        document.querySelector('.diagnostic .content').innerHTML = patient.diagnose_content
        document.querySelector('#report-time').innerText = patient.report_time
        document.querySelector('.hospital').innerText = hospitalName ?? '未知机构名称'
        ipcs.print()
    }

    //异步IPC
    const ipcs = {
        print() {
            const { pn } = getUrlParams(window.location.href)
            const printerName = decodeURIComponent(pn)
            window.$.send('PLUGIN-PRINT', { printerName })
        }
    }

    window.onload = () => {
        queryData()
    }

</script>


</html>